import 'package:flutter/material.dart';
import 'package:aweb5/base/BaseWidget.dart';
import 'package:aweb5/pages/GotoPay.dart';
import 'package:aweb5/pages/UseCoupon.dart';
import 'SelectAddress.dart';
class Submit extends BaseWidget {
  @override
  State<Submit> createState() => SubmitState();
}

class SubmitState extends BaseWidgetState<Submit> {
  int listCount = 5;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    init(context);
    return Scaffold(
      appBar: appBarWithBack("提交订单"),
      body: Column(
        children: <Widget>[
          top(),
          Divider(
            height: 10,
            color: Color(0xfff4f4f4),
          ),
          Expanded(
              child: ListView.builder(
            itemBuilder: (con, ind) {
              return list(ind);
            },
            itemCount: listCount + 1,
          )),

          Divider(
            height: 51,
            color: Colors.white,
          )
          //getItem()
        ],
      ),
      bottomSheet: Container(
        height: 49.0,
        // padding: EdgeInsets.only(left: 10.0, right: 10.0),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Expanded(
                flex: 2,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    SizedBox(width: 10),
                    Text(
                      "总计",
                      style: TextStyle(
                          color: Color(0xff2d2d2d),
                          fontSize: 14,
                          fontWeight: FontWeight.bold),
                    ),
                    Text(
                      "¥9",
                      style: TextStyle(color: Color(0xffff0000), fontSize: 18),
                    )
                  ],
                )),
            Expanded(
              flex: 2,
              child: InkWell(
                child: Container(
                  height: 49,
                  decoration: BoxDecoration(color: Color(0xffff8900)),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        "去结算",
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 16.0,
                        ),
                      ),
                    ],
                  ),
                ),
                onTap: () {
                  navigatorState.push(new MaterialPageRoute(builder: (context) {
                    return GotoPay();
                  }));
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget getItem() {
    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(left: 0, right: 0),
          height: 100,
          color: Colors.white,
          padding: EdgeInsets.only(left: 10, right: 10, top: 10),
          child: Row(
            children: <Widget>[
              Image.asset(
                "assets/banner1.png",
                width: 80,
                height: 80,
                fit: BoxFit.fill,
              ),
              SizedBox(
                width: 10,
              ),
              Expanded(
                child: Column(
                  //crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(
                      "好喝的牛奶111111111111111111111111111111111111111111111",
                      style: TextStyle(color: Colors.black, fontSize: 14),
                      overflow: TextOverflow.ellipsis,
                      maxLines: 2,
                    ),
                    Expanded(child: Text("")),
                    Row(
                      children: <Widget>[
                        Column(
                          children: <Widget>[
                            Text(
                              "规格",
                              style: TextStyle(
                                  fontSize: 9, color: Color(0xff888888)),
                            ),
                            Text(
                              "1",
                              style: TextStyle(
                                  color: Color(0xffff0036), fontSize: 16),
                            )
                          ],
                        ),
                        Expanded(child: Text("")),
                        Text(
                          "x2",
                          style:
                              TextStyle(color: Color(0xff2d2d2d), fontSize: 13),
                        )
                      ],
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          padding: EdgeInsets.only(
            left: 10,
            right: 10,
          ),
          color: Colors.white,
          child: TextField(
            decoration: InputDecoration(
                hintText: "输入备注内容",
                hintStyle: TextStyle(color: Color(0xff888888), fontSize: 11),
                border: InputBorder.none),
          ),
        ),
        Divider(
          height: 1,
          color: Color(0xffe9e9e9),
        )
      ],
    );
    ;
  }

  Widget top() {
    return
      InkWell(
        child:Container(
          color: Colors.white,
          padding: EdgeInsets.only(left: 10, right: 10),
          height: 81,
          alignment: Alignment.centerLeft,
          child: Row(
            children: <Widget>[
              Image.asset(
                "assets/location1.png",
                width: 31,
                height: 31,
              ),
              SizedBox(
                width: 13,
              ),
              Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        "收货人： 某某某 1111111",
                        style: TextStyle(color: Color(0xff2d2d2d), fontSize: 12),
                      ),
                      Text(
                        "收货地址：北京 北京市平谷区紫贵庄园9-10号",
                        style: TextStyle(color: Color(0xff2d2d2d), fontSize: 12),
                        overflow: TextOverflow.ellipsis,
                      ),
                    ],
                  )),
              Image.asset(
                "assets/rightarrow.png",
                width: 10,
                height: 19,
              )
            ],
          ),
        ) ,
        onTap: (){
          navigatorState.push(new MaterialPageRoute(builder: (con){
            return SelectAddress();
          }));
        },
      );

  }

  Widget list(ind) {
    if (ind < listCount) {
      return Column(
        children: <Widget>[
          Container(
            height: 37,
            margin: EdgeInsets.only(left: 10),
            alignment: Alignment.centerLeft,
            child: Row(
              children: <Widget>[
                Image.asset(
                  "assets/ab.png",
                  width: 15,
                  height: 13,
                ),
                SizedBox(
                  width: 3,
                ),
                Text(
                  "花花牛",
                  style: TextStyle(color: Color(0xff4b4b4b), fontSize: 12),
                )
              ],
            ),
          ),
          Divider(
            height:1,
            color: Color(0xffe9e9e9),
          ),
          ListView.builder(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (c, index) {
              return getItem();
            },
            itemCount: 10,
          )
        ],
      );
    } else {
      return bottom();
    }
  }

  Widget remark() {
    return Container(
      height: 62,
      margin: EdgeInsets.only(left: 10, top: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            "订单备注",
            style: TextStyle(color: Color(0xff4b4b4b), fontSize: 12),
          ),
          TextField(
            decoration: InputDecoration(
                hintText: "输入备注内容",
                hintStyle: TextStyle(color: Color(0xff888888), fontSize: 11),
                border: InputBorder.none),
          )
        ],
      ),
      color: Colors.white,
    );
  }

  Widget count() {
    return Container(
      height: 32,
      color: Colors.white,
      padding: EdgeInsets.only(left: 10, top: 10, right: 10),
      child: Row(
        children: <Widget>[
          Text(
            "商品金额",
            style: TextStyle(color: Color(0xff2d2d2d), fontSize: 12),
          ),
          Expanded(child: Text("")),
          Text(
            "¥",
            style: TextStyle(color: Color(0xff2d2d2d), fontSize: 12),
          )
        ],
      ),
    );
  }

  Widget fee() {
    return Container(
      height: 32,
      color: Colors.white,
      padding: EdgeInsets.only(left: 10, top: 10, right: 10),
      child: Row(
        children: <Widget>[
          Text(
            "商品运费",
            style: TextStyle(color: Color(0xff2d2d2d), fontSize: 12),
          ),
          Expanded(child: Text("")),
          Text(
            "¥",
            style: TextStyle(color: Color(0xff2d2d2d), fontSize: 12),
          )
        ],
      ),
    );
  }

  Widget coup() {
    return InkWell(
      child: Container(
        color: Colors.white,
        height: 39,
        padding: EdgeInsets.all(10),
        child: Row(
          children: <Widget>[
            Image.asset(
              "assets/youhui.png",
              width: 33,
              height: 15,
            ),
            Expanded(child: Text("")),
           Container(
                height: 16,
                decoration: BoxDecoration(
                    color: Color(0xffff4300),
                    borderRadius: BorderRadius.circular(2)),
                child: Text(
                  "2张可用",
                  style: TextStyle(color: Colors.white, fontSize: 12),
                ),
                alignment: Alignment.center,
                padding: EdgeInsets.only(left: 2, right: 2),
              ),

            SizedBox(
              width: 5,
            ),
            Image.asset(
              "assets/rightarrow.png",
              width: 8,
              height: 15,
            )
          ],
        ),
      ),
      onTap: (){
        navigatorState.push(new MaterialPageRoute(builder: (con){
          return UseCoupon();
        }));
      },
    );
  }

  Widget bottom() {
    return Column(
      children: <Widget>[
        remark(),
        Divider(
          height:1,
          color: Color(0xffe9e9e9),
        ),
        count(),
        fee(),
        Divider(
          height:1,
          color: Color(0xffe9e9e9),
        ),
        coup(),
      ],
    );
  }

  Widget listItem() {}
}
